<style>
    #febs-classify xm-select {
        min-height: 30px;
        line-height: 30px;
    }
    #febs-classify xm-select > .xm-label .scroll .label-content {
        display: flex;
        padding: 0 30px 0 10px;
    }
</style>
<div class="layui-fluid layui-anim febs-anim" id="febs-classify" lay-title="签核分类配置">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="classify-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">分类编号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="billstdNo" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">分类名字</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="billstdNm" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                             <!--       <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">创建时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="time" id="classify-createTime" class="layui-input">
                                        </div>
                                    </div>-->

                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                                     shiro:hasAnyPermissions="classify:add,classify:update,classify:password:reset">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="classifyBaseTable" lay-data="{id: 'classifyBaseTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="classify-option">
    <span shiro:lacksPermission="classify:view,classify:update,classify:delete">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>
    <a lay-event="detail" shiro:hasPermission="classify:view"><i
            class="layui-icon febs-edit-area febs-green">&#xe7a5;</i></a>
    <a lay-event="edit" shiro:hasPermission="classify:update"><i
            class="layui-icon febs-edit-area febs-blue">&#xe7a4;</i></a>
    <a lay-event="del" shiro:hasPermission="classify:delete"><i
            class="layui-icon febs-edit-area febs-red">&#xe7f9;</i></a>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs', 'xmSelect'], function () {
        let $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#febs-classify'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'lastDate', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo;

        form.render();

        initTable();

        laydate.render({
            elem: '#classify-createTime',
            range: true,
            trigger: 'click'
        });

        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                let checkStatus = table.checkStatus('classifyBaseTable');
                if (name === 'add') {
                    febs.modal.open('新增分类', 'approval/classify/add', {
                        btn: ['提交', '重置'],
                        area: $(window).width() <= 750 ? '95%' : '50%',
                        yes: function (index, layero) {
                            $('#classify-add').find('#submit').trigger('click');
                        },
                        btn2: function () {
                            $('#classify-add').find('#reset').trigger('click');
                            return false;
                        }
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的分类');
                    } else {
                        febs.modal.confirm('删除分类', '确定删除该分类？', function () {
                            let billstdNos = [];
                            layui.each(checkStatus.data, function (key, item) {
                                billstdNos.push(item.billstdNo)
                            });
                            deleteBases(billstdNos.join(','));
                        });
                    }
                }
            },
            options: [{
                name: 'add',
                title: '新增分类',
                perms: 'classify:add'
            }, {
                name: 'delete',
                title: '删除分类',
                perms: 'classify:delete'
            }, /*{
                name: 'export',
                title: '导出Excel',
                perms: 'classify:export'
            }*/]
        });

        table.on('tool(classifyBaseTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                febs.modal.view('分类信息', 'approval/classify/detail/' + data.billstdNo, {
                    area: $(window).width() <= 750 ? '95%' : '660px'
                });
            }
            if (layEvent === 'del') {
                febs.modal.confirm('删除分类', '确定删除【 '+data.billstdNm +'】类别？', function () {
                    deleteBases(data.billstdNo);
                });
            }
            if (layEvent === 'edit') {
                febs.modal.open('修改分类', 'approval/classify/update/' + data.billstdNo, {
                    id: data.billstdNo,
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#classify-update').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });

        table.on('sort(R)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            console.log(params)
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            createTimeTo = null;
            createTimeFrom = null;
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}, initSort: sortObject});
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'classifyBaseTable',
                url: ctx + 'classify/list',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'billstdNo', title: '分类编号',minWidth: 100},
                    {field: 'billstdNm', title: '分类名称', minWidth: 100},
                    /*{field: 'runPrg', title: 'runPrg', minWidth: 100},
                    {field: 'callPrgnm', title: 'callPrgnm', minWidth: 165},*/
                    {title: '操作', toolbar: '#classify-option', minWidth: 140}
                ]]
            });
        }

        function getQueryParams(flag) {
            let params = $searchForm.serializeJson();
    /*        let lastDate = params.time;
            if (lastDate) {
                createTimeFrom = lastDate.split(' - ')[0];
                createTimeTo = lastDate.split(' - ')[1];
            }
            params.invalidate_ie_cache = new Date();
            params.createTimeFrom = createTimeFrom;
            params.createTimeTo = createTimeTo;*/
            return params;
        }

        function deleteBases(billstdNos) {
            febs.get(ctx + 'classify/delete/' + billstdNos, null, function () {
                febs.alert.success('删除分类成功');
                $query.click();
            });
        }
    })
</script>